/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.ec.coupon.entity.Coupon
   Module Description   :

   Date Created      : 2009/11/24
   Original Author   : jeff.ma
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.ec.coupon.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

import com.yaodian100.core.common.entity.BaseEntity;

/**
 * 禮券主檔
 * 
 * @author jeff.ma
 */
@javax.persistence.Entity(name = "coupon")
@javax.persistence.Table(name = "EC_COUPON_MAIN")
public class Coupon extends BaseEntity {

	/** serialVersionUID */
	private static final long serialVersionUID = -4520316205691404979L;

	private final static String SEPARATOR = ",";

	public enum ApplyRangType {
		/** 全館適用 */
		ALL("全馆适用"),
		/** 特定目錄 */
		CATEGORY("特定目录"),
		/** 特定商品 */
		PRODUCT("特定商品");
		private String desc;

		ApplyRangType(String desc) {
			this.desc = desc;
		}

		public String getDesc() {
			return desc;
		}

		public String getCode() {
			return name();
		}
	}

	public enum Status {
		/** 建立 */
		INIT("建立"),
		/** 被使用 */
		USED("被使用"),
		/** 停用 */
		INACTIVE("停用");
		private String desc;

		Status(String desc) {
			this.desc = desc;
		}

		public String getDesc() {
			return desc;
		}

		public String getCode() {
			return name();
		}
	}

	@Id
	@GeneratedValue(generator = "gen_uuid")
	@GenericGenerator(name = "gen_uuid", strategy = "uuid")
	@Column(name = "COUPON_UUID")
	private String uuid;
	@Column(name = "COUPON_NAME", length = 20)
	private String name;
	@Column(name = "COUPON_DESC", length = 500)
	private String description;
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "COUPON_TYPE")
	private ApplyRangType applyRangeType = ApplyRangType.ALL;
	@Column(name = "COUPON_TYPE_EXT", length = 2000)
	private String applyRangeTypeExtension;

	@Column(name = "COUPON_AMOUNT")
	private long amount;
	@Column(name = "COUPON_FACE_VALUE")
	private BigDecimal faceValue;
	@Enumerated(EnumType.ORDINAL)
	@Column(name = "COUPON_STATUS")
	private Status status = Status.INIT;

	@Column(name = "START_DATE")
	private Date startDate;

	@Column(name = "END_DATE")
	private Date endDate;
	/** budget, 预算归属, 維護於選單 Menu 'Budget' */
	@Column(name = "BUDGET", length = 2)
	private String budget = "A";

	/**
	 * 最低商品價格
	 */
	@Column(name = "MINIMUM_PRODUCT_PRICE")
	private BigDecimal minimumProductPrice;

	/**
	 * 是否限同一會員充值乙次
	 */
	@Column(name = "IS_ONCE")
	@Type(type = "yes_no")
	private Boolean isOnce;

	/**
	 * 
	 */
	@Column(name = "ACT_LINK")
	private String activityLink;

	/** default constructor */
	public Coupon() {
		super();
	}

	/**
	 * @return the uuid
	 */
	public String getUuid() {
		return uuid;
	}

	/**
	 * @param uuid the uuid to set
	 */
	@SuppressWarnings("unused")
	private void setUuid(String uuid) {
		this.uuid = uuid;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the applyRangeType
	 */
	public ApplyRangType getApplyRangeType() {
		return applyRangeType;
	}

	/**
	 * @param applyRangeType the applyRangeType to set
	 */
	public void setApplyRangeType(ApplyRangType applyRangeType) {
		this.applyRangeType = applyRangeType;
	}

	/**
	 * @return the applyRangeTypeExtension
	 */
	public String getApplyRangeTypeExtension() {
		return applyRangeTypeExtension;
	}

	/**
	 * @param applyRangeTypeExtension the applyRangeTypeExtension to set
	 */
	public void setApplyRangeTypeExtension(String applyRangeTypeExtension) {
		if (applyRangeTypeExtension != null) {
			applyRangeTypeExtension = StringUtils.remove(applyRangeTypeExtension, "\r\n");
			applyRangeTypeExtension = StringUtils.remove(applyRangeTypeExtension, "\n");
			applyRangeTypeExtension = StringUtils.remove(applyRangeTypeExtension, "\r");
			applyRangeTypeExtension = StringUtils.remove(applyRangeTypeExtension, System.getProperty("line.separator"));
			applyRangeTypeExtension = StringUtils.remove(applyRangeTypeExtension, " ");
		}
		this.applyRangeTypeExtension = applyRangeTypeExtension;
	}

	/**
	 * @return the applyRangeTypeExtension
	 */
	public String[] getApplyRangeTypeExtensionArray() {
		if (applyRangeTypeExtension != null) {
			return StringUtils.split(applyRangeTypeExtension, SEPARATOR);
		} else {
			return new String[0];
		}
	}

	/**
	 * @param applyRangeTypeExtension the applyRangeTypeExtension to set
	 */
	public void setApplyRangeTypeExtensionArray(String[] applyRangeTypeExtensionArray) {
		if (applyRangeTypeExtensionArray != null) {
			this.applyRangeTypeExtension = StringUtils.join(applyRangeTypeExtensionArray, SEPARATOR);
		}
	}

	/**
	 * @return the amount
	 */
	public long getAmount() {
		return amount;
	}

	/**
	 * @param amount the amount to set
	 */
	public void setAmount(long amount) {
		this.amount = amount;
	}

	/**
	 * @return the faceValue
	 */
	public BigDecimal getFaceValue() {
		return faceValue;
	}

	/**
	 * @param faceValue the faceValue to set
	 */
	public void setFaceValue(BigDecimal faceValue) {
		this.faceValue = faceValue;
	}

	/**
	 * @return the status
	 */
	public Status getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(Status status) {
		this.status = status;
	}

	/**
	 * 
	 * @return 最低商品價格
	 */
	public BigDecimal getMinimumProductPrice() {
		return this.minimumProductPrice;
	}

	/**
	 * 
	 * @param minimumProductPrice 最低商品價格
	 */
	public void setMinimumProductPrice(BigDecimal minimumProductPrice) {
		this.minimumProductPrice = minimumProductPrice;
	}

	/**
	 * 是否限同一會員充值乙次
	 * 
	 * @return
	 */
	public Boolean getIsOnce() {
		return this.isOnce;
	}

	/**
	 * 
	 * @param isOnce 是否限同一會員充值乙次
	 */
	public void setIsOnce(Boolean isOnce) {
		this.isOnce = isOnce;
	}

	/**
	 * 相關活動連結
	 */
	public String getActivityLink() {
		return this.activityLink;
	}

	public void setActivityLink(String activityLink) {
		this.activityLink = activityLink;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Coupon [uuid=");
		builder.append(uuid);
		builder.append(", status=");
		builder.append(status);
		builder.append(", name=");
		builder.append(name);
		builder.append(", description=");
		builder.append(description);
		builder.append(", faceValue=");
		builder.append(faceValue);
		builder.append(", amount=");
		builder.append(amount);
		builder.append(", applyRangeType=");
		builder.append(applyRangeType);
		builder.append(", applyRangeTypeExtension=");
		builder.append(applyRangeTypeExtension);
		builder.append("]");
		return builder.toString();
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public String getBudget() {
		return budget;
	}

	public void setBudget(String budget) {
		this.budget = budget;
	}

}
